<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Grid;
use Encore\Admin\Form;

use Illuminate\Http\Request;
use \Illuminate\Support\Facades\Input;
use App\Models\Account\PlayerActModel;
use App\Models\Account\PlayerOnline;
use App\Models\Area;
use App\Models\Account\BehaviorSingle;
use App\Models\Account\Behavior;
use App\Models\Account\BehaviorThew;
use App\Models\Account\BehaviorCoins;

use App\Admin\Extra\Search\Html;
// 玩家行为日志
class BehaviorController extends Controller
{
    
    public function anyGroupBehavior() {
        return Admin::content(function (Content $content) {
            $req = Input::all();
            $content->header('player log static');
            $content->description('.....');
            
            $content->row(Html::append(
                BehaviorSingle::getBarButtons($req)
            ));
            $grid = Admin::grid(BehaviorSingle::class, function(Grid $grid)use($req){
                
                $grid->actions(function($actions){
                    $actions->disableDelete();
                    $actions->disableEdit();
                    // $actions->append('<a href="'.url('admin/areaorder/list-all?cp_area='). $actions->row->cp_area .'"><i class="glyphicon glyphicon-eye-open"></i></a>');
                });
                $grid->op('op')->display(function($value)use($req){
                    $req['op'] = $this->op;
                    $url = \App\Service\Common::build_url_query(url()->current(),  $req);
                    $show = "<p><a href=\"$url\">$value</a></p>";
                    $show .= "<p>$this->op_alias</p>";
                    return $show;
                });
                $grid->op_module('Module')->display(function($value)use($req){
                    $show = "<p>$value</p>";
                    $show .= "<p>$this->op_m_alias</p>";
                    return $show;
                });
                // $grid->op_alias('op_alias');
                // $grid->op_module('op_module');
                // $grid->op_m_alias('ModuleAlias');
                $grid->times('Times')->display(function($value)use($req) {
                    $req['op'] = $this->op;
                    $req['op_module[]'] = $this->op_module;
                    $url = \App\Service\Common::build_url_query('/admin/player/behavior',  $req);
                    return '<a href="'.$url.'">'.$value . '</a>';
                });
                $grid->diamonds('Cost');
                // $grid->op_time('Time')->display(function($value) {
                //     return date("Y-m-d H:i:s", $value);
                // });
                $grid->filter(function ($filter){
                    $filter->equal('player_id', 'PlayerID');
                    $filter->equal('area', 'Area')->select(\App\Models\Area::areaSelectData(0));//
                    $filter->equal('ops', 'Operator')->multipleSelect(\App\Models\Account\Behavior::getOpAlias());
                    // $filter->equal('op_module', 'Module')->multipleSelect(\App\Models\Account\Behavior::getOpmoduleAlias());
                    $filter->between('op_time', 'Operator Time')->datetime();
                });
            });
            $content->row($grid->render());
        });       
    }

    // 玩家行为日志
    public function anyBehaviorCoin(Request $request) {
        if (!$request->get('ops')) {
            $request->offsetSet('ops', ['S.DIAMOND_REDUCE']);
        }
        $area = $request->get('area');
        $area_info= \App\Models\Area::areaInfo($area) ?: [];
    return Admin::content(function (Content $content) use($area_info) {

        $content->header('player behavior coin detail');
        
        $content->description("[".$area_info['areaId'].":".$area_info['name']."]");
        $content->row(Html::append(
            Behavior::getCoinButtons(Input::all())
        ));
        $grid = Admin::grid(Behavior::class, function(Grid $grid){
            $grid->id('# ID');
            $grid->column('player_id');
            $grid->op('op');
            $grid->op_alias('op_alias');
            $grid->op_module('op_module');
            $grid->op_m_alias('ModuleAlias');
            $grid->column('level');
            $grid->column('diamond');
            $grid->op_val_1('Value1');
            $grid->item_alias('ItemAlias');
            $grid->op_val_2('Value2');
            $grid->op_val_3('Value3');
            $grid->op_time('Time')->display(function($value) {
                return date("Y-m-d H:i:s", $value);
            });
            $grid->filter(function ($filter){
                $filter->equal('player_id', 'PlayerID');
                $filter->equal('area', 'Area')->select(\App\Models\Area::areaSelectData(0));//
                $filter->in('ops', 'Operator')->multipleSelect(\App\Models\Account\Behavior::getOpAlias());
                $filter->in('op_module', 'Modules')->multipleSelect(\App\Models\Account\Behavior::getOpmoduleAlias());
                $filter->between('op_time', 'Operator Time')->datetime();
            });
        });

        $content->row($grid->render());
    });       

    }

    // 
    public function anyBehaviorPannel(Request $request) {
        return Admin::content(function (Content $content) use($area_info) {
            $req = Input::all();
            $class = 'btn-info btn-goto';
            $buttons = [];
            $param = [
                'area' => '',
                'op_time' => ['start'=> date("Y-m-d",time() - 30 * 86400)],
                'op_module' => 'S.common.buy_thew',
            ];
            // 购买体力
            $url = \App\Service\Common::build_url_query('/admin/behavior/thew-count', $param);
            $buttons[] = Html::button('购买体力', $url, ' btn-200  '. $class);
            // 货币
            // 钻石--
            $param['op'] = 'S.DIAMOND_REDUCE';
            $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
            $buttons[] = Html::button('钻石--', $url, ' btn-200 '. $class . ' btn-warning');
            // 钻石++
            $param['op'] = 'S.DIAMOND_ADD';
            $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
            $buttons[] = Html::button('钻石++', $url, ' btn-200  '. $class);
            // 红钻--
            $param['op'] = 'S.TICKET_REDUCE';
            $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
            $buttons[] = Html::button('红钻--', $url, ' btn-200  '. $class . ' btn-warning');
            // 红钻++
            $param['op'] = 'S.TICKET_ADD';
            $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
            $buttons[] = Html::button('红钻++', $url, ' btn-200  '. $class);
            // 金币--
            $param['op'] = 'S.GOLD_REDUCE';
            $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
            $buttons[] = Html::button('金币--', $url, ' btn-200  '. $class . ' btn-warning');
            // 金币++
            $param['op'] = 'S.GOLD_ADD';
            $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
            $buttons[] = Html::button('金币++', $url, ' btn-200  '. $class);
            $content->row(Html::append($buttons));
            
        });
    }

    public function anyThewCount(Request $request) {
        $area = $request->get('area');
        $area_info= \App\Models\Area::areaInfo($area) ?: [];
    return Admin::content(function (Content $content) use($area_info) {

        $content->header('player behavior thew static');
        
        $content->description("[".$area_info['areaId'].":".$area_info['name']."]");
        // $content->row(Html::append(
        //     Behavior::getCoinButtons(Input::all())
        // ));
        $grid = Admin::grid(BehaviorThew::class, function(Grid $grid){
           
            $grid->times('Times');
            $grid->num('PlayerNums')->display(function($value){
                $param = [
                    'area' => [Input::get('area')],
                    'player_id' => implode(',',$this->player_id),
                ];
                $url = \App\Service\Common::build_url_query('/admin/player/role-list', $param);
                return '<a href = "'.$url.'" >' . $value . '</a>';
            });
            
            $grid->filter(function ($filter){
                // $filter->equal('player_id', 'PlayerID');
                $filter->equal('area', 'Area')->select(\App\Models\Area::areaSelectData(0));//
                $filter->equal('vip', 'Vip');
                $filter->equal('level', 'Level');
                // $filter->in('ops', 'Operator')->multipleSelect(\App\Models\Account\Behavior::getOpAlias());
                // $filter->in('op_module', 'Modules')->multipleSelect(\App\Models\Account\Behavior::getOpmoduleAlias());
                $filter->between('op_time', 'Operator Time')->datetime();
            });
            $grid->disableActions();
        });

        $content->row($grid->render());
    });       
    }

    public function anyCostCount(Request $request) {
        $area = $request->get('area');
        $area_info= \App\Models\Area::areaInfo($area) ?: [];
    return Admin::content(function (Content $content) use($area_info) {
        $op_alias = \App\Models\Account\Behavior::getOpAlias();
        $content->header("货币统计:".$op_alias[Input::get('op')]);
        
        $content->description("[".$area_info['areaId'].":".$area_info['name']."]");
        // $content->row(Html::append(
        //     Behavior::getCoinButtons(Input::all())
        // ));
        $grid = Admin::grid(BehaviorCoins::class, function(Grid $grid){
           
            $grid->cost('cost');
            $grid->num('PlayerNums')->display(function($value){
                $param = [
                    'area' => [Input::get('area')],
                    'player_id' => implode(',',$this->player_id),
                ];
                $url = \App\Service\Common::build_url_query('/admin/player/role-list', $param);
                return '<a href = "'.$url.'" >' . $value . '</a>';
            });
            
            $grid->filter(function ($filter){
                
                $filter->equal('area', 'Area')->select(\App\Models\Area::areaSelectData(0));//
                $filter->equal('vip', 'Vip');
                $filter->equal('level', 'Level');
                // $filter->in('ops', 'Operator')->multipleSelect(\App\Models\Account\Behavior::getOpAlias());
                // $filter->in('op_module', 'Modules')->multipleSelect(\App\Models\Account\Behavior::getOpmoduleAlias());
                $filter->between('op_time', 'Operator Time')->datetime();
                // 或者在filter回调里面操作`$filter`实例
                $filter->expand();
            });
            
        });

        $req = Input::all();
        $class = 'btn-info btn-goto';
        $buttons = [];
        $param = [
            'area' => '',
            'op_time' => ['start'=> date("Y-m-d",time() - 30 * 86400)],
            'op_module' => 'S.common.buy_thew',
        ];
        $param = array_merge($param, $req);
        // 购买体力
        $url = \App\Service\Common::build_url_query('/admin/behavior/thew-count', $param);
        $buttons[] = Html::button('购买体力', $url, ' btn-200  '. $class);
        // 货币
        // 钻石--
        $param['op'] = 'S.DIAMOND_REDUCE';
        $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
        $buttons[] = Html::button('钻石--', $url, ' btn-200 '. $class . ' btn-warning');
        // 钻石++
        $param['op'] = 'S.DIAMOND_ADD';
        $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
        $buttons[] = Html::button('钻石++', $url, ' btn-200  '. $class);
        // 红钻--
        $param['op'] = 'S.TICKET_REDUCE';
        $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
        $buttons[] = Html::button('红钻--', $url, ' btn-200  '. $class . ' btn-warning');
        // 红钻++
        $param['op'] = 'S.TICKET_ADD';
        $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
        $buttons[] = Html::button('红钻++', $url, ' btn-200  '. $class);
        // 金币--
        $param['op'] = 'S.GOLD_REDUCE';
        $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
        $buttons[] = Html::button('金币--', $url, ' btn-200  '. $class . ' btn-warning');
        // 金币++
        $param['op'] = 'S.GOLD_ADD';
        $url = \App\Service\Common::build_url_query('/admin/behavior/cost-count', $param);
        $buttons[] = Html::button('金币++', $url, ' btn-200  '. $class);
        $content->row(Html::append($buttons));
        $content->row($grid->render());
    });       
    }
}